package com.jfl.base;

import java.util.List;
import java.util.Map;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.extension.service.IService;
import com.github.pagehelper.PageInfo;
import com.jfl.exception.BusinessException;
import com.jfl.exception.ValidateException;

/**
 * 基类Service
 * 
 * @author 赵炎
 * @version [V1.00, 2018年11月29日]
 * @since V1.00
 */
public interface BaseService<T extends BaseModel> extends IService<T>
{
    /** 
     * 修改
     * @param record
     * @param userId
     * @return
     * @throws BusinessException
     * @throws ValidateException
     * @see [类、类#方法、类#成员]
     */
    @Transactional
    T update(T record) throws BusinessException, ValidateException;
    
    /** 
     * 逻辑删除
     * @param ids 删除的id
     * @param userId 用户id
     * @throws BusinessException
     * @throws ValidateException
     * @see [类、类#方法、类#成员]
     */
    @Transactional
    void del(List<Long> ids, Long userId) throws BusinessException, ValidateException;
    
    /** 
     * 逻辑删除单条
     * @param id
     * @param userId
     * @throws BusinessException
     * @throws ValidateException
     * @see [类、类#方法、类#成员]
     */
    @Transactional
     void del(Long id, Long userId)  throws BusinessException, ValidateException;
    
    /** 
     * 物理删除
     * @param id
     * @throws BusinessException
     * @throws ValidateException
     * @see [类、类#方法、类#成员]
     */
    @Transactional
     void delete(Long id) throws BusinessException, ValidateException;
    
    /** 
     * 物理删除
     * @param entity
     * @return
     * @throws BusinessException
     * @throws ValidateException
     * @see [类、类#方法、类#成员]
     */
    @Transactional
     Integer deleteByEntity(T entity) throws BusinessException, ValidateException;
    
    /** 
     * 物理删除
     * @param columnMap
     * @return
     * @throws BusinessException
     * @throws ValidateException
     * @see [类、类#方法、类#成员]
     */
    @Transactional
     Integer deleteByMap(Map<String, Object> columnMap) throws BusinessException, ValidateException;
    
    /** 
     * 根据id查询
     * @param id
     * @return
     * @see [类、类#方法、类#成员]
     */
    T queryById(Long id);
    
    /** 
     * 分页查询
     * @param params
     * @return
     * @see [类、类#方法、类#成员]
     */
    @Cacheable
    PageInfo<T> query(Map<String, Object> params);
    
    /** 
     * 
     * @param entity
     * @param rowBounds
     * @return
     * @see [类、类#方法、类#成员]
     */
    @Cacheable
    PageInfo<T> query(T entity, PageInfo<T> rowBounds);
    
    /** 
     * 动态Sql
     * @param params 实体类字段 非数据库字段
     * @return
     */
    @Cacheable
    List<T> queryList(Map<String, Object> params);
    
    @Cacheable
    List<T> queryList(List<Long> params);
    
    @Cacheable
    <K> List<K> queryList(List<Long> ids, Class<K> cls);
    
    @Cacheable
    List<T> queryList(T entity);
    
    @Cacheable
    PageInfo<T> queryFromDB(Map<String, Object> params);
    
    @Cacheable
    PageInfo<T> queryFromDB(T entity, PageInfo<T> rowBounds);
    
    @Cacheable
    List<T> queryListFromDB(Map<String, Object> params);
    
    /** 
     * 分页查询
     * @param request 封装的分页请求对象
     * @param record 实体类
     * @return
     */
    @Cacheable
    PageInfo<T> selectList(PageRequest request, T record);
    
    
}
